#pragma once

#ifndef _CGLOBAL_H_
#define _CGLOBAL_H_

#include "CNetwork.h"
#include "CChar.h"
#include <vector>
#include "pThreads/semaphore.h"
#include "CSemaphore.h"
#include "Utils/T2List.h"
#include "Utils/T2AvlList.h"
#include "Utils/T2DLinkedList.h"

class CStringKeyCI;

class CGlobal 
{
private: 
	static T2List<unsigned int,CChar*>* m_charListById;
	static T2List<CStringKeyCI,CChar*>* m_charListByName;
	static T2List<long long,CChar*>* m_charListByIpUdpport;
	static T2List<unsigned short,CChar*>* CGlobal::m_charListByIpTargId;//this should be a zone based list !

	static void checkLists(void);
public:
	static CChar* getCCharById(unsigned int charId);
	static CChar* getCCharByName(char* charName);
	static CChar* getCCharByIpUdpport(ULONG ip, u_short port);
	static CChar* CGlobal::getCCharByTargId(unsigned short targId);
	static CChar* getCCharAt(unsigned int position);
	static unsigned int getCCharListSize();

	static char addCChar(CChar* newChar);
	static char removeCChar(CChar* delChar);
	static char linkCCharWithUdpPort( ULONG ip, u_short port, CChar* newChar );
	static char unlinkCCharWithUdpPort(ULONG ip, u_short port);
	static char linkCCharWithTargId( unsigned short targId, CChar* newChar );
	static char CGlobal::unlinkCCharWithTargId( unsigned short targId );
	static T2List<unsigned int,CChar*>* CGlobal::getCCharList(void);

	//semaphore to lock the character list
	static CSemaphore* CGlobal::charListSemaphore;

	//semaphore to lock the NPC list
	static CSemaphore* CGlobal::NPCListSemaphore;

	//Waits until the character list is free
	static void CGlobal::waitCharList(void);

	//Waits until the character list is free
	static void CGlobal::exitCharList(void);

	//Waits until the NPC list is free
	static void CGlobal::waitNPCList(void);

	//Waits until the NPC list is free
	static void CGlobal::exitNPCList(void);

	//exp rate modification
	static float CGlobal::expRate;
	
	//drop rate modification
	static float CGlobal::dropRate;

	//Name of your server
	static unsigned char CGlobal::serverName[16];

	//Server message
	static char * CGlobal::serverMessage;

	//List for Char Removal
	//List for all CChar Objects that need to be deleted
	static std::vector<CChar*> CGlobal::charRemovalList;

	//semaphore to lock the removal list
	static CSemaphore* CGlobal::charRemovalListSemaphore;

	//Waits until the character removal list is free
	static void CGlobal::waitCharRemovalList(void);

	//Waits until the character removal list is free
	static void CGlobal::exitCharRemovalList(void);

	//
	static std::vector<struct connections> CGlobal::lobbyConList;

	//semaphore to lock the removal list
	static CSemaphore* CGlobal::lobbyConListSemaphore;

	static void lockLobbyConList(void);
	static void unlockLobbyConList(void);

};
#endif